﻿#define _CRT_SECURE_NO_WARNINGS 1
#include "game.h"

int main()
{
	int a = 0;
	srand(time(NULL));	//随机数种子
	do					//游戏主循环
	{
		Menu();			//打印一个简易的菜单
		printf("请选择-> ");
		scanf("%d", &a);
		switch (a)
		{
		case 1:
			Game();		//游戏主程序
			break;
		case 0:
			printf("成功退出！\n");
			break;
		default:
			printf("非法输入！请重新输入：\n");
			break;
		}
	} while (a != 0);
	

	return 0;
}

void Game(void)
{
	char result = 0;
	char chess[ROW][LOW] = { 0 };	//存储玩家和电脑的行动记录
	Init(chess, ROW, LOW);			//初始化棋盘
	PrintChess(chess, ROW, LOW);	//打印游戏棋盘
	while (1)		//游戏主循环
	{
		PeoChess(chess);	//玩家行动
		PrintChess(chess, ROW, LOW);
		result = WinChess(chess);
		if (result != 'c')
		{
			break;
		}
		CompuChess(chess);	//电脑行动
		PrintChess(chess, ROW, LOW);
		result = WinChess(chess);
		if (result != 'c')
		{
			break;
		}
	}
	switch (result)
	{
	case '*':
		printf("玩家胜利！\n");
		break;
	case '#':
		printf("电脑胜利！\n");
		break;
	case 's':
		printf("平局！\n");
		break;
	}
}